<?php

global $db;
global $cf;

require('configuration.php');
require('libraries/craw/database.php');
require('libraries/craw/query.php');
require('libraries/craw/router.php');
require('libraries/craw/theme.php');
require('libraries/craw/string.php');
require('libraries/craw/parse.php');
//require('libraries/craw/craw.php');
require('libraries/craw/craw_tutorialspoint_com.php');
require('libraries/craw/craw_tienganhhangngay_com.php');
	
$cf = new JConfig();
$db = new database($cf->host,$cf->user,$cf->password,$cf->db,$cf->dbprefix,$cf->offline);
//putenv ('UPDATEXOSO=TRUE');
#Chá»‰ cho phÃ©p má»™t script thá»±c thi vÃ o má»™t thá»�i Ä‘iá»ƒm


if (getenv('UPDATEXOSO') != false ) {
	//die ('Craw Ä‘ang hoáº¡t Ä‘á»™ng, vui lÃ²ng thá»­ láº¡i sau'); 
} else {
	//putenv ('UPDATEXOSO=TRUE');
}

#KhÃ´ng giá»›i háº¡n thá»�i gian craw data
set_time_limit(0);
ignore_user_abort(true);

#Khá»Ÿi táº¡o output buffering
ob_end_clean();
		
if(ob_get_level() == 0) {
	ob_start();
}

#####################################

require('libraries/craw/craw.tpl.php');

echo str_pad(' ',4096)."<br />\n";
echo "<pre>";	

#cháº¿ Ä‘á»™ craw dá»¯ liá»‡u tá»« link hoáº·c tá»« html láº¥y tá»« database
$task = router::getParam('task','link');
$date = router::getParam('date',date('Y-m-d',strtotime("-1 day")));
$time = date("H:i");
#Parse from database
switch($task) {
	case 'lich' : crawCalendar();	break;
	case 'live' : crawLive();		break;
	
	case 'link' : 
		//if($time > "19:30"){
			crawLink($date); 	
		//}
		break;
	case 'data' : crawData($date);	break;
	case 'giacmo': crawGM(); break;
	case 'xsmb':
		xs::getXSMB($date);break;
	case 'tutorialspoint_com_get_categories':
		craw_tutorialspoint_com::get_categories();
		break;
	case 'tienganhhangngay_com_get_cats':
		//die('====');
		craw_tienganhhangngay_com::get_cats();
		break;
	case 'tienganhhangngay_com_update_total_page':
		//die('====');
		craw_tienganhhangngay_com::update_total_page();
		break;
	case 'tienganhhangngay_com_get_title_article':
		craw_tienganhhangngay_com::get_title_article();
		break;
	case 'tienganhhangngay_com_get_content_article':
		craw_tienganhhangngay_com::get_content_article();
		break;
	case 'tienganhhangngay_com_update_name_ascii_cat':
		craw_tienganhhangngay_com::update_name_ascii_cat();
		break;
	case 'tienganhhangngay_com_update_title_link':
		craw_tienganhhangngay_com::update_title_link();
		break;
}

echo "</pre>";

#####################################

ob_end_flush();

#End execute 

echo '</body>';
echo '</html>';
exit;
 
?>
